using System;
using System.IO;
using RaisingStudio.SmallBasicCompiler.Expressions;
using RaisingStudio.SmallBasicCompiler.Statements;

namespace RaisingStudio.SmallBasicCompiler
{
	internal class Program
	{
		private static void Main(string[] args)
		{
			Program program = new Program();
			if (args.Length != 1)
			{
                Console.WriteLine("Usage: RaisingStudio.SmallBasicCompiler.exe <SB File>");
				return;
			}
			program.Run(args[0]);
		}

		private void Run(string file)
		{
			if (!File.Exists(file))
			{
				Console.WriteLine("{0} doesn't exist.", file);
				return;
			}
			using (StreamReader streamReader = new StreamReader(file))
			{
				Compiler compiler = new Compiler();
				Path.GetDirectoryName(file);
				string fileNameWithoutExtension = Path.GetFileNameWithoutExtension(file);
				compiler.Build(streamReader, fileNameWithoutExtension, Directory.GetCurrentDirectory());
				Console.Write(file);
				Console.WriteLine(": {0} errors.", compiler.Parser.Errors.Count);
				Console.WriteLine();
			}
		}
	}
}
